#include <iostream>
#include <cstring>
#include <cerrno>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "comm.h"

using namespace std;

int main()
{
    int wfd = open(FILENAME, O_WRONLY);
    if (wfd < 0)
    {
        cerr << "errno: " << errno << ", errstring: " << strerror(errno) << endl;
        return 1;
    }
    cout << "open fifo success... write" << endl;

    string message;
    while (true)
    {
        cout << "Please Enter# ";
        getline(cin, message);

        ssize_t s = write(wfd, message.c_str(), message.size());
        if (s < 0)
        {
            cerr << "errno: " << errno << ", errstring: " << strerror(errno) << endl;
            break;
        }
    }

    close(wfd);
    cout << "close fifo success... write" << endl;

    return 0;
}
